package gemini.jsf;

import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;

/**
 *
 * @author ASaburov
 */
public class CountryListener implements ValueChangeListener {

    private static final String US = "United States";

    public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
        FacesContext context = FacesContext.getCurrentInstance();

        if (US.equals((String) event.getNewValue())) {
            context.getViewRoot().setLocale(Locale.US);
        } else {
            context.getViewRoot().setLocale(Locale.CANADA);
        }

        context.renderResponse();
    }
}
